package com.gao.mongo.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoId;

import java.util.Date;
import java.util.List;

/**
 * 1.符合索引声明
 * @CompoundIndex( def = "{'userid': 1, 'nickname': -1}")
 *
 *
 *
 * ClassName: Cart
 * Description:
 * date: 2021/8/27 21:56
 *
 * @author gaoxi
 * @since JDK 1.8
 */
@Document(collection = "cart")
@Data
public class Cart {

    /**
     * 主键标识，该属性的值会自动对应mongodb的主键字段"_id"，
     * 如果该属性名就叫“id”,则该注解可以省略，否则必须写
     */
    @Id
    private String id;

    /**
     * @Indexed 声明此字段是索引字段
     */
    @Indexed
    private Integer userId;

    private String goodId;

    private String goodName;

    private Integer num;

    private List<String> attrs;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss SSS")
    private Date createAt;

}
